package cn.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 线程pool的重命名
 */
@Slf4j
public class Test2 {
    public static void main(String[] args) {
        ExecutorService pool= Executors.newFixedThreadPool(2, new ThreadFactory() {
            private AtomicInteger name=new AtomicInteger(1);
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r,"自定义线程"+name.getAndIncrement()+"号");
            }
        });
        pool.execute(new Thread(()->{
            log.info("1");
        }));
        pool.shutdown();
        pool.execute(new Thread(()->{
            log.info("2");
        }));

    }
}
